package com.yang.Runner;

import com.yang.config.RedisBloomFilter;
import com.yang.domain.entity.Shop;
import com.yang.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
 * 将所有存在的店铺数据存放到布隆过滤器中
 * </p>
 * @author yang
 * @date 2023/8/13
 */
@Component
public class BloomFilterRunner implements CommandLineRunner {

    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private RedisBloomFilter<Long> redisBloomFilter;
    /**
     * 店铺缓存预热
     * @param args 参数
     */
    @Override
    public void run(String... args) {
        List<Shop> shopList = shopMapper.selectList(null);

        List<Long> idList = shopList.stream().map(Shop::getId).collect(Collectors.toList());

        idList.forEach(id -> redisBloomFilter.put(id));
    }
}
